const db = wx.cloud.database()
const teamlistCollection = db.collection('teamlist')
//Page Object
Page({
  data: {
    openid: '',
    myteamList: [],
    applyinglist: []
  },
  //options(Object)
  onLoad: function (options) {
    wx.showLoading({
      title: '数据加载中……',
    })
    let that = this
    this.setData({
      openid: wx.getStorageSync('OPENID'),
    })
    wx.cloud.init({env: 'cloud1-5glocnmp62950062'})
    wx.cloud.callFunction({
      name: 'getmyTeam',
      success: function (res) {
        let myteamList = res.result.myjoinTeamResult.data
        that.setData({
          myteamList: myteamList,
        })
        console.log(res)
        wx.hideLoading({
          success: (res) => {},
        })
      },
      fail: function () {
        wx.showToast({
          title: '获取数据失败，请稍后再试',
          icon: 'none',
        })
      },
      complete: res=>{
      }
    })
  },

  onReady: function () {
    wx.cloud.init({env: 'cloud1-5glocnmp62950062'})
    wx.cloud.callFunction({
      name: 'getapplylist',
      complete: res=>{
        console.log('callFunction test result:',res)
        let applyinglist = res.result.applicationResult.list.filter(item=>item._openid==this.data.openid).map(item=>{return item.applicationlist[0]})
        console.log('applicationResult:',applyinglist)
        this.setData({
          applyinglist:applyinglist
        })
      }
    })
  }
})
